package com.hw.swagger2.controller;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
public class UserController {

	private static Logger log=LoggerFactory.getLogger(UserController.class);
	
    @ApiOperation(value = "swagger2接口的实例",notes = "swagger2接口的实例,参考了简书：https://www.jianshu.com/p/406e9d203300",httpMethod = "GET")
    @ApiImplicitParam(dataType = "string",name = "name",value = "姓名",required = true)
//    spring通过produces设置响应头
    @RequestMapping(value = "/user",produces="application/json;charset=UTF-8")
    public String user(HttpServletResponse res,String name) {

//    	spring 重设了响应头，在这里设置不起作用
//    	res.setHeader("Content-Type", "application/json;charset=UTF-8");
    	String msg="hello "+ name;
    	log.info(msg);
        return msg;
    }
    
    
    @ApiOperation(value = "admin接口",notes = "admin 接口调用",httpMethod = "GET")
    @ApiImplicitParam(dataType = "string",name = "name",value = "角色",required = true)
    @RequestMapping(value = "/admin",produces="application/json;charset=UTF-8")
    public String admin(HttpServletResponse res, String name) {

//    	res.setHeader("Content-Type", "application/json;charset=UTF-8");
    	String msg="hello admin："+ name;
    	log.info(msg);
        return msg;
    }
}